00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef GENCLS_HPP
00011 #define GENCLS_HPP
00012 #include "gridpack/component/data_collection.hpp"
00013 #include "gridpack/parser/dictionary.hpp"
00014 #include "gridpack/utilities/string_utils.hpp"
00015 namespace gridpack {
00016 namespace parser {
00017 template <class _data_struct> class GenclsParser
00018 {
00019 public:
00020
00021
00022
00023 explicit GenclsParser()
00024 {
00025 }
00026
00027
00028
00029
00030 virtual ~GenclsParser()
00031 {
00032 }
00033
00034
00035
00036
00037
00038
00039
00040 void extract(_data_struct &data_struct,
00041 gridpack::component::DataCollection *data, int g_id)
00042 {
00043 double rval;
00044 std::string stmp;
00045
00046 if (!data->getValue(GENERATOR_MODEL,&stmp,g_id)) {
00047 data->addValue(GENERATOR_MODEL, data_struct.model, g_id);
00048 } else {
00049 data->setValue(GENERATOR_MODEL, data_struct.model, g_id);
00050 }
00051
00052
00053 if (!data->getValue(GENERATOR_INERTIA_CONSTANT_H,&rval,g_id)) {
00054 data->addValue(GENERATOR_INERTIA_CONSTANT_H,
00055 data_struct.inertia, g_id);
00056 } else {
00057 data->setValue(GENERATOR_INERTIA_CONSTANT_H,
00058 data_struct.inertia, g_id);
00059 }
00060
00061
00062 if (!data->getValue(GENERATOR_DAMPING_COEFFICIENT_0,&rval,g_id)) {
00063 data->addValue(GENERATOR_DAMPING_COEFFICIENT_0,
00064 data_struct.damping, g_id);
00065 } else {
00066 data->setValue(GENERATOR_DAMPING_COEFFICIENT_0,
00067 data_struct.damping, g_id);
00068 }
00069
00070
00071 if (!data->getValue(GENERATOR_TRANSIENT_REACTANCE,&rval,g_id)) {
00072 data->addValue(GENERATOR_TRANSIENT_REACTANCE,
00073 data_struct.reactance, g_id);
00074 } else {
00075 data->setValue(GENERATOR_TRANSIENT_REACTANCE,
00076 data_struct.reactance, g_id);
00077 }
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 void parse(std::vector<std::string> &split_line,
00087 gridpack::component::DataCollection *data, int g_id)
00088 {
00089 double rval;
00090 int nstr = split_line.size();
00091
00092 std::string stmp, model;
00093 gridpack::utility::StringUtils util;
00094 model = util.trimQuotes(split_line[1]);
00095 util.toUpper(model);
00096 if (!data->getValue(GENERATOR_MODEL,&stmp,g_id)) {
00097 data->addValue(GENERATOR_MODEL, model.c_str(), g_id);
00098 } else {
00099 data->setValue(GENERATOR_MODEL, model.c_str(), g_id);
00100 }
00101
00102
00103 if (nstr > 3) {
00104 if (!data->getValue(GENERATOR_INERTIA_CONSTANT_H,&rval,g_id)) {
00105 data->addValue(GENERATOR_INERTIA_CONSTANT_H,
00106 atof(split_line[3].c_str()), g_id);
00107 } else {
00108 data->setValue(GENERATOR_INERTIA_CONSTANT_H,
00109 atof(split_line[3].c_str()), g_id);
00110 }
00111 }
00112
00113
00114 if (nstr > 4) {
00115 if (!data->getValue(GENERATOR_DAMPING_COEFFICIENT_0,&rval,g_id)) {
00116 data->addValue(GENERATOR_DAMPING_COEFFICIENT_0,
00117 atof(split_line[4].c_str()), g_id);
00118 } else {
00119 data->setValue(GENERATOR_DAMPING_COEFFICIENT_0,
00120 atof(split_line[4].c_str()), g_id);
00121 }
00122 }
00123
00124 if (nstr > 5) {
00125 if (!data->getValue(GENERATOR_TRANSIENT_REACTANCE,&rval,g_id)) {
00126 data->addValue(GENERATOR_TRANSIENT_REACTANCE,
00127 atof(split_line[5].c_str()), g_id);
00128 } else {
00129 data->setValue(GENERATOR_TRANSIENT_REACTANCE,
00130 atof(split_line[5].c_str()), g_id);
00131 }
00132 }
00133 }
00134
00135
00136
00137
00138
00139
00140 void store(std::vector<std::string> &split_line,_data_struct &data)
00141 {
00142
00143 int o_idx;
00144 o_idx = atoi(split_line[0].c_str());
00145 data.bus_id = o_idx;
00146
00147
00148 gridpack::utility::StringUtils util;
00149 std::string tag = util.clean2Char(split_line[2]);
00150 strcpy(data.gen_id, tag.c_str());
00151
00152 std::string sval;
00153
00154 sval = util.trimQuotes(split_line[1]);
00155 util.toUpper(sval);
00156
00157
00158 strcpy(data.model, sval.c_str());
00159
00160 int nstr = split_line.size();
00161
00162 if (nstr > 3) {
00163 data.inertia = atof(split_line[3].c_str());
00164 }
00165
00166
00167 if (nstr > 4) {
00168 data.damping = atof(split_line[4].c_str());
00169 }
00170
00171
00172 if (nstr > 5) {
00173 data.reactance = atof(split_line[5].c_str());
00174 }
00175 }
00176 };
00177 }
00178 }
00179 #endif